package com.flower.service.impl;

import com.flower.mapper.SupplierMapper;
import com.flower.model.dto.SupplierDTO;
import com.flower.model.dto.SupplierPageQueryDTO;
import com.flower.model.entity.Supplier;
import com.flower.result.PageResult;
import com.flower.service.SupplierService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@SuppressWarnings("all")
/**
 *@ClassName SupplierServiceImpl
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/6/13 16:59
 *@Version 1.0
 */
@Slf4j
@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;
    @Override
    public PageResult pageQuery(SupplierPageQueryDTO supplierPageQueryDTO) {
        PageHelper.startPage(supplierPageQueryDTO.getPageNum(), supplierPageQueryDTO.getPageSize());
        Page<Supplier> page = supplierMapper.pageQuery(supplierPageQueryDTO);
        long total = page.getTotal();
        List<Supplier> records = page.getResult();
        return new PageResult(total, records);

    }

    @Override
    public void addOrUpdate(SupplierDTO supplierDTO) {
        if (supplierDTO.getId() == null) {
            log.info("添加供应商信息");
            supplierMapper.add(supplierDTO);
        } else {
            log.info("修改供应商信息");
            supplierMapper.update(supplierDTO);
        }
    }

    @Override
    public void deleteSupplier(Integer id) {
        supplierMapper.delSupplierById(id);
    }

    @Override
    public void deleteSupplierBatch(List<Integer> ids) {
        ids.forEach(id -> supplierMapper.delSupplierById(id));
    }

    @Override
    public List<SupplierDTO> list() {
        return supplierMapper.list();
    }
}
